
local yuanlue = fk.CreateSkill {
  name = "lingling__yuanlue",
}

Fk:loadTranslationTable{
  ["lingling__yuanlue"] = "远掠",
  [":lingling__yuanlue"] = "出牌阶段限一次，你可以获得一名其他角色一张牌，其下回合首次对你造成的伤害+1。",

  ["#lingling__yuanlue"] = "远掠：获得一名其他角色一张牌，其下回合首次对你造成的伤害+1",

  ["@@lingling__yuanlue"] = "远掠",
}

yuanlue:addEffect("active", {
  anim_type = "offensive",
  prompt = "#lingling__yuanlue",
  max_phase_use_time = 1,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 1,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 and to_select ~= player and not player:isNude()
  end,
  on_use = function(self, room, use)
    local from = use.from
    local to = use.tos[1]
    room:obtainCard(from, room:askToChooseCard(from, {
      target = to,
      flag = "he",
      skill_name = yuanlue.name
    }), nil, fk.ReasonPrey, from, yuanlue.name)
    room:addTableMark(to, "@@lingling__yuanlue", from.id)
  end
})
yuanlue:addEffect(fk.DamageCaused, {
  is_delay_effect = true,
  anim_type = "negative",
  can_trigger = function(self, event, target, player, data)
    if target == player and not player.dead and player.room:getCurrent() == player and
      table.contains(player:getTableMark("@@lingling__yuanlue"), data.to.id) then
      return #player.room.logic:getActualDamageEvents(1, function(e)
        local damage = e.data
        return player == damage.from and data.to == damage.to
      end, Player.HistoryTurn) == 0
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:removeTableMark(player, "@@lingling__yuanlue-turn", data.to.id)
    data:changeDamage(1)
  end
})
yuanlue:addEffect(fk.TurnEnd, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@@lingling__yuanlue") ~= 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@@lingling__yuanlue", 0)
  end
})

return yuanlue
